// pages/addressList/addressList.js
var app=getApp()
Page({
  data:{},
  onLoad:function(options){
    var that=this
    var url=app.data.url
    var openid=wx.getStorageSync('user').openid
    //收货地址列表
    wx.request({
      url: '' + url +'/Shop/UserCenter/GetReceiptAddress2',
      data: { openid: '123',storeid:'6002'},
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        that.setData({
          list:res.data.Rows
        })
      },
      error: function (res) {
        console.log(res)
      }
    })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  /**
   * 跳转至新增地址页面
   */
  toAddressAdd: function(){
    wx.navigateTo({
      url: '../address-add/address-add'
    })
  },
  /**
   * 长按显示操作
   */
  actionSheetTap: function (e) {
    var url=app.data.url
    var id = e.currentTarget.dataset.index
    wx.showActionSheet({
      itemList: ['编辑', '删除'],
      success: function (e) {
        console.log(e.tapIndex);
        if(e.tapIndex == 0){
          wx.navigateTo({
            url: '../address-add/address-add?id='+id+''
          });
        }
        if (e.tapIndex == 1) {
          wx.request({
            url: '' + url + '/shop/order/deletereceiptaddress',
            data: { id:id},
            header: {
              'Content-Type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              if(res.Status=='ok'){
                wx.redirectTo({
                  url: '../address-list/address-list',
                })
              }
            },
            error: function (res) {
              console.log(res)
            }
          })
        }
      }
    })
  }
})